package com.quan.sdk.weixin.tools;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.quan.common.utils.HttpClientUtil;
import com.quan.sdk.weixin.common.WeixinContext;

/**
 * 微信菜单工具类
 * @author yhaoquan
 *
 */
public class MenuTools {

	private static Logger logger = LoggerFactory.getLogger(MenuTools.class);
	
	/**
	 * 自定义菜单创建接口
	 * <br>方式：POST
	 * <br>参数：
	 * <br>&nbsp;&nbsp;&nbsp; access_token 全局唯一接口调用凭据
	 */
	public static String MENU_CREATE_URL = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s" ;
	
	
	/**
	 * 推送菜单到微信
	 * @param accessToken
	 * @param menuJson
	 * @return
	 */
	public static JSONObject pushMenuToWeiXin(String menus) {
		String url = String.format(MENU_CREATE_URL, WeixinContext.getAccessToken()) ;
		String response = HttpClientUtil.post(url, menus, "utf-8");
		logger.info("推送菜单到微信：{}", response);
		return JSON.parseObject(response) ;
	}
	
}
